package com.cnpinxi.service;

import com.cnpinxi.dao.ResourceMapper;
import com.cnpinxi.domain.Resource;
import com.cnpinxi.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Baggio on 2017-11-15.
 */
@Service
public class ResourceServiceImpl implements com.cnpinxi.service.ResourceService {
    @Autowired
    ResourceMapper resourceMapper;

    @Override
    public List<Resource> getResourceList(Map<String, String> map) {
        return resourceMapper.getResourceList(map);
    }

    @Override
    public Resource getResource(Map<String, String> map) {
        return resourceMapper.getResource(map);
    }

    @Override
    public void modifyResource(Resource resource) {
        Long resourceId = resource.getTid();
        if (resourceId == null) {
            insertResource(resource);
        } else {
            updateResource(resource);
        }
    }

    private void insertResource(Resource resource) {
        resourceMapper.insertResource(resource);
    }

    private void updateResource(Resource resource) {
        resourceMapper.updateResourceById(resource);
    }
}
